//
// Created by francklinson on 2021/12/31 AT 15:20.
//
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;

class Solution {
public:
    bool checkAlmostEquivalent(string word1, string word2) {
        vector<int> counter(26, 0);
        for (char i : word1) {
            ++counter[i - 'a'];
        }
        for (char i:word2) {
            --counter[i - 'a'];
        }
        return all_of(counter.begin(),counter.end(),[](int x){
            return (x <=3 && x >= -3);
        });
    }
};

int main() {
    Solution solution;
    cout << solution.checkAlmostEquivalent("aaaa", "bccb") << endl;
    cout << solution.checkAlmostEquivalent("abcdeef", "abaaacc") << endl;
    cout << solution.checkAlmostEquivalent("cccddabba", "babababab") << endl;
    return 0;
}

